package com.github.skystardust.lotteryex.lottery.bundle;

import com.github.skystardust.lotteryex.gui.LotteryAnimation;
import com.github.skystardust.lotteryex.lottery.LotteryItem;
import com.github.skystardust.lotteryex.lottery.bundle.profile.LotteryProfile;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.configuration.serialization.ConfigurationSerializable;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@EqualsAndHashCode
@ToString
public class LotteryBundle implements ConfigurationSerializable {
    private UUID uuid;
    private Map<LotteryItem, LotteryProfile> lotteryItemProfileMap;
    private LotteryAnimation lotteryAnimation;

    public LotteryBundle(UUID uuid, Map<LotteryItem, LotteryProfile> lotteryItemProfileMap, LotteryAnimation lotteryAnimation) {
        this.uuid = uuid;
        this.lotteryItemProfileMap = lotteryItemProfileMap;
        this.lotteryAnimation = lotteryAnimation;
    }

    public LotteryBundle(Map<String, Object> stringObjectMap) {
        this.uuid = UUID.fromString((String) stringObjectMap.get("uuid"));
        this.lotteryItemProfileMap = (Map<LotteryItem, LotteryProfile>) stringObjectMap.get("lotteryItemProfileMap");
        this.lotteryAnimation = (LotteryAnimation) stringObjectMap.get("lotteryAnimation");
    }

    private LotteryBundle(Builder builder) {
        setUuid(builder.uuid);
        setLotteryItemProfileMap(builder.lotteryItemProfileMap);
        setLotteryAnimation(builder.lotteryAnimation);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public Map<LotteryItem, LotteryProfile> getLotteryItemProfileMap() {
        return lotteryItemProfileMap;
    }

    public void setLotteryItemProfileMap(Map<LotteryItem, LotteryProfile> lotteryItemProfileMap) {
        this.lotteryItemProfileMap = lotteryItemProfileMap;
    }

    public LotteryAnimation getLotteryAnimation() {
        return lotteryAnimation;
    }

    public void setLotteryAnimation(LotteryAnimation lotteryAnimation) {
        this.lotteryAnimation = lotteryAnimation;
    }

    @Override
    public Map<String, Object> serialize() {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("uuid", uuid.toString());
        stringObjectHashMap.put("lotteryItemProfileMap", lotteryItemProfileMap);
        stringObjectHashMap.put("lotteryAnimation", lotteryAnimation);
        return stringObjectHashMap;
    }

    public static final class Builder {
        private UUID uuid;
        private Map<LotteryItem, LotteryProfile> lotteryItemProfileMap;
        private LotteryAnimation lotteryAnimation;

        private Builder() {
        }

        @Nonnull
        public Builder withUuid(@Nonnull UUID val) {
            uuid = val;
            return this;
        }

        @Nonnull
        public Builder withLotteryItemProfileMap(@Nonnull Map<LotteryItem, LotteryProfile> val) {
            lotteryItemProfileMap = val;
            return this;
        }

        @Nonnull
        public Builder withLotteryAnimation(@Nonnull LotteryAnimation val) {
            lotteryAnimation = val;
            return this;
        }

        @Nonnull
        public LotteryBundle build() {
            return new LotteryBundle(this);
        }
    }
}
